var datatable;// 定义一个全局的dataTable
var attachChar;
var epsAttachChar;
var areaAttachChar;
var d;
//第二版变更开始**********
//查询参数
var param = new Object({
	init:function(){
		this.timeSize = ''
		this.beginDate = ''
		this.endDate = ''
		this.netYuan = ''
		this.area_status=0	
		this.area = ''
		this.tac_status=0	
		this.tac=''
		this.eNodeBID_status=0	
		this.eNodeBID = ''
		this.village_status=0	
		this.village=''
	},
	setParam:function(){
		this.init()
		this.timeSize = $('input:radio[name="timeSize"]:checked').val();
		this.beginDate = $('#beginDate').val()
		this.endDate = $('#endDate').val()
		this.netYuan = $('#netYuan').val()
		if($("#area").is(':checked')){
			  this.area=$("#area_value").val();
			  this.area_status=1;
		}
		if($("#tac").is(':checked')){
			  this.tac=$("#tac_value").val();
			  this.tac_status=1;
		}
		if($("#eNodeBID").is(':checked')){
			this.eNodeBID=$("#eNodeBID_value").val();
			this.eNodeBID_status=1;
		}
		if($("#village").is(':checked')){
			this.village=$("#village_value").val();
			this.village_status=1;
		}
	}
});
//第二版变更结束**********
$(function() {
	//网元下拉
	$("#netYuan").combobox();
	$('#table tbody').on('click', 'tr', function() {
		if ($(this).hasClass('selected')) {
			$(this).removeClass('selected');
		} else {
			datatable.$('tr.selected').removeClass('selected');
			$(this).addClass('selected');
		}
	});
	
	showArearList("area_value");
	if($("#jspType").val() == 'kqi_evalution_zcxq_more'){
		var timeSize_link = $('#timeSize_link').val();
		$("input[type='radio'][name=timeSize][value='"+timeSize_link+"']").attr("checked",true);
		$("#area_value").val($("#city_code_link").val());
	}
})

function getList() {
	
	var startTime=$("#beginDate").val();  
    var endTime=$("#endDate").val();  
    if(!checkEndTime()){
		layer.alert("开始时间不能大于结束时间！", {
			icon : 3,
			offset: '100px'
		});
		return;
	};
	
	param.setParam();
	
	$("#tbodyId").remove();
	$('#table').append($("<tbody id='tbodyId'></tbody>"));
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.destroy();
	}
	datatable = $('#table')
			.DataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : true, // 翻页功能
						"iDisplayLength" : 50,
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"ordering": true, //排序功能
						"bSort" : true, // 排序功能
						"bInfo" : true,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						"iDisplayLength" : 50,
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
//						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../..//businessAnalysis/netelement/getNetElement",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$
									.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"param" : JSON.stringify(param)
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.pageDate);
											d = resp.allData;
										}
									});
						},
						columns : [
								{
									data : "report_date"
								},
								{
									data : "mme_dev"
								},

								{
									data : "city_code",
									"visible": false
								},
								{
									data : "tac",
									"visible": false
								},
								{
									data : "enodeb_id",
									"visible": false
								},
								{
									data : "cell_name",
									"visible": false
								},
								{
									data : "user_num",
									"visible": false
										
								},
								{
									data : "traffic_sum",
									"visible": false
								},
								{
									data : "output_octets",
									"visible": false
								},
								{
									data : "input_octets",
									"visible": false
								},
								{
									data : "output_packet",
									"visible": false
								}, 
								{
									data : "input_packet",
									"visible": false
								},
								
								//必选
								{
									data : "atta_ratio"
								},
								{
									data : "tau_ratio"
								},
								{
									data : "pdn_ratio"
								},
								{
									data : "session_ratio"
								},
								//可选
								{
									data : "tcp_ratio",
									"visible": false
								},
								{
									data : "dns_ratio",
									"visible": false
								}, {
									data : "download_ratio",
									"visible": false
								}, {
									data : "frist_pack_time_delay",
									"visible": false
								}, {
									data : "frist_page_time_delay",
									"visible": false
								}, {
									data : "qoe",
									"visible": false
								}]

					});
			
			if($("#area").is(':checked')){
				var column = datatable.column($("#area").attr('data-column'));
				
				var column1 = datatable.column($("#user_num").attr('data-column'));
				var column2 = datatable.column($("#traffic_sum").attr('data-column'));
				var column3 = datatable.column($("#output_octets").attr('data-column'));
				var column4 = datatable.column($("#input_octets").attr('data-column'));
				var column5 = datatable.column($("#output_packet").attr('data-column'));
				var column6 = datatable.column($("#input_packet").attr('data-column'));
				
				var column7 = datatable.column($("#tcp_ratio").attr('data-column'));
				var column8 = datatable.column($("#dns_ratio").attr('data-column'));
				var column9 = datatable.column($("#download_ratio").attr('data-column'));
				var column10 = datatable.column($("#frist_pack_time_delay").attr('data-column'));
				var column11 = datatable.column($("#frist_page_time_delay").attr('data-column'));
				var column12 = datatable.column($("#qoe").attr('data-column'));
			    column.visible(true);
			    column1.visible(true);
			    column2.visible(true);
			    column3.visible(true);
			    column4.visible(true);
			    column5.visible(true);
			    column6.visible(true);
			    column7.visible(true);
			    column8.visible(true);
			    column9.visible(true);
			    column10.visible(true);
			    column11.visible(true);
			    column12.visible(true);
			}
			
			
			if($("#tac").is(':checked')){
				var column = datatable.column($("#tac").attr('data-column'));
				var column1 = datatable.column($("#user_num").attr('data-column'));
				var column2 = datatable.column($("#traffic_sum").attr('data-column'));
				var column3 = datatable.column($("#output_octets").attr('data-column'));
				var column4 = datatable.column($("#input_octets").attr('data-column'));
				var column5 = datatable.column($("#output_packet").attr('data-column'));
				var column6 = datatable.column($("#input_packet").attr('data-column'));
				
				var column7 = datatable.column($("#tcp_ratio").attr('data-column'));
				var column8 = datatable.column($("#dns_ratio").attr('data-column'));
				var column9 = datatable.column($("#download_ratio").attr('data-column'));
				var column10 = datatable.column($("#frist_pack_time_delay").attr('data-column'));
				var column11 = datatable.column($("#frist_page_time_delay").attr('data-column'));
				var column12 = datatable.column($("#qoe").attr('data-column'));
			    column.visible(true);
			    column1.visible(true);
			    column2.visible(true);
			    column3.visible(true);
			    column4.visible(true);
			    column5.visible(true);
			    column6.visible(true);
			    column7.visible(true);
			    column8.visible(true);
			    column9.visible(true);
			    column10.visible(true);
			    column11.visible(true);
			    column12.visible(true);
			}
			if($("#eNodeBID").is(':checked')){
				var column = datatable.column($("#eNodeBID").attr('data-column'));
				var column1 = datatable.column($("#user_num").attr('data-column'));
				var column2 = datatable.column($("#traffic_sum").attr('data-column'));
				var column3 = datatable.column($("#output_octets").attr('data-column'));
				var column4 = datatable.column($("#input_octets").attr('data-column'));
				var column5 = datatable.column($("#output_packet").attr('data-column'));
				var column6 = datatable.column($("#input_packet").attr('data-column'));
				
				var column7 = datatable.column($("#tcp_ratio").attr('data-column'));
				var column8 = datatable.column($("#dns_ratio").attr('data-column'));
				var column9 = datatable.column($("#download_ratio").attr('data-column'));
				var column10 = datatable.column($("#frist_pack_time_delay").attr('data-column'));
				var column11 = datatable.column($("#frist_page_time_delay").attr('data-column'));
				var column12 = datatable.column($("#qoe").attr('data-column'));
			    column.visible(true);
			    column1.visible(true);
			    column2.visible(true);
			    column3.visible(true);
			    column4.visible(true);
			    column5.visible(true);
			    column6.visible(true);
			    column7.visible(true);
			    column8.visible(true);
			    column9.visible(true);
			    column10.visible(true);
			    column11.visible(true);
			    column12.visible(true);
			}
			if($("#village").is(':checked')){
				var column = datatable.column($("#village").attr('data-column'));
				var column1 = datatable.column($("#user_num").attr('data-column'));
				var column2 = datatable.column($("#traffic_sum").attr('data-column'));
				var column3 = datatable.column($("#output_octets").attr('data-column'));
				var column4 = datatable.column($("#input_octets").attr('data-column'));
				var column5 = datatable.column($("#output_packet").attr('data-column'));
				var column6 = datatable.column($("#input_packet").attr('data-column'));
				
				var column7 = datatable.column($("#tcp_ratio").attr('data-column'));
				var column8 = datatable.column($("#dns_ratio").attr('data-column'));
				var column9 = datatable.column($("#download_ratio").attr('data-column'));
				var column10 = datatable.column($("#frist_pack_time_delay").attr('data-column'));
				var column11 = datatable.column($("#frist_page_time_delay").attr('data-column'));
				var column12 = datatable.column($("#qoe").attr('data-column'));
			    column.visible(true);
			    column1.visible(true);
			    column2.visible(true);
			    column3.visible(true);
			    column4.visible(true);
			    column5.visible(true);
			    column6.visible(true);
			    column7.visible(true);
			    column8.visible(true);
			    column9.visible(true);
			    column10.visible(true);
			    column11.visible(true);
			    column12.visible(true);
			}

}


function resetQueryForm() {
	$('#queryForm')[0].reset();
}

function forwordInterfaceFailure(dateType,failureTypeInfo,jspType,mme_name,city_code,tai,
		enodeb_id,enodeb_name,cell_name,group_id,msisdn,user_terminal,terminal_brand,apn_name,paramDate) {
	var url = "/kpi/interfaceFailureLink/index?dateType=" + dateType +"&failureTypeInfo="+failureTypeInfo + "&jspType="+jspType +"&mme_name="+mme_name
	+ "&paramDate=" + paramDate + "&interfaceType=2&signalType=1&type=" + param.dimension +"&tac_status="+param.tac_status
	+ "&eNodeBID_status=" + param.eNodeBID_status +"&village_status="+param.village_status
	+ "&city_code=" +city_code+"&tai="+tai+"&enodeb_id="+enodeb_id+"&enodeb_name="+enodeb_name  
	+ "&cell_name=" +cell_name+"&group_id="+group_id+"&msisdn="+msisdn+"&user_terminal="+user_terminal+"&terminal_brand="+terminal_brand+"&apn_name="+apn_name;   
	linkTab("接口故障", url);
}

function checkEndTime(){  
    var startTime=$("#beginDate").val();  
    var start=new Date(startTime.replace("-", "/").replace("-", "/"));  
    var endTime=$("#endDate").val();  
    var end=new Date(endTime.replace("-", "/").replace("-", "/"));  
    if(end<start){  
        return false;  
    }  
    return true;  
}